<?php

namespace Home\Controller;
use Org\Nx\Page;
use Think\Controller;

class UserController extends CommonController {
    public function _initialize(){
        //检测是否登录
        parent::_initialize();
       //下面是针对登录注册 手机版的检测方法
       $token = $_SERVER['HTTP_TOKEN']?$_SERVER['HTTP_TOKEN']:I('token');
		$where_token['token'] = $token;
		$token_log = M('Token')->where($where_token)->find();
		if(!$token_log){
			$data_return['status'] = -101;
			$data_return['info'] = 'token不存在';
			return $this->ajaxReturn($data_return);
		}
		$where_user['UE_ID'] = $token_log['uid'];
		$user = M('User')->where($where_user)->find();
		if(!$user){
			$data_return['status'] = -102;
			$data_return['info'] = '查无此人';
			return $this->ajaxReturn($data_return);
		}
		$data_return['uid'] = $token_log['uid'];
		$data_return['user'] = $user;
		$this->user = $user;
		$this->uid = $user['ue_id'];
		return $data_return;
    }
	//参加者
	public function canjiazhe() {
		$this->display ('canjiazhe');
	}
	//我的
	public function getUsername(){
	   $data_return['username'] = $this->user['ue_account'];
	   $data_return['status'] = 1;
	   $this->ajaxReturn($data_return);
	}
	//推荐人
	public function tuijianren() {
	    $list = M('User')
	    ->field('UE_ID,UE_account,UE_accName,UE_verMail,UE_money,UE_regTime')
	    ->where(['ue_account'=>$this->user['ue_accname']])
	    ->find();
		$data_return['status'] = 1;
		$data_return['user'] = $list;
		$this->ajaxReturn($data_return);
	}
	//我的页面
	public function wodeyemian() {
		$this->display ('wodeyemian');
	}
	public function getUser(){
	    $uid =$this->uid;
	     $list = M('User')
	    ->where(['uid'=>$uid])->find();
	    $list['tuijian_email'] = M('User')
	    ->where(['UE_account'=>$list['ue_accname']])->find()['ue_vermail'];
	    $data['data'] = $list;
	    $data['status'] = 1;
/* 	    $data = array(
	        0=>array(
	            'name'=>'Name',
	            'value'=>$list['ue_account'],
	            'group'=>'一般',
	            'editor'=>'disabled',
	        ),
	        1=>array(
	            'name'=>'级别',
	            'value'=>$list['levelname']?$list['levelname']:'普通会员',
	            'group'=>'一般',
	            'editor'=>'disabled',
	            /* 'key'=>'levelname'
	        ),
	        2=>array(
	            'name'=>'邮箱',
	            'value'=>$list['ue_vermail'],
	            'group'=>'一般',
	            'editor'=>'disabled',
	        ),
	        3=>array(
	            'name'=>'注册时间',
	            'value'=>$list['ue_regtime'],
	            'group'=>'一般',
	            'editor'=>'disabled',
	            /* 'key'=>'ue_theme' 
	        ),
	        4=>array(
	            'name'=>'微信',
	            'value'=>$list['weixin'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	             'key'=>'weixin'
	        ),
	        5=>array(
	            'name'=>'支付宝',
	            'value'=>$list['zfb'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'zfb'
	        ),
	        6=>array(
	            'name'=>'推荐人用户名',
	            'value'=>$list['ue_accname'],
	            'group'=>'推荐人信息',
	            'editor'=>'disabled',
	        ),
	        7=>array(
	            'name'=>'推荐人邮箱',
	            'value'=>$list['tuijian_email'],
	            'group'=>'推荐人信息',
	            'editor'=>'disabled',
	        ),
	        8=>array(
	            'name'=>'推荐人级别',
	            'value'=>'普通会员',
	            'group'=>'推荐人信息',
	            'editor'=>'disabled',
	        ),
	        9=>array(
	            'name'=>'Skype',
	            'value'=>$list['skype'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'Skype'
	        ),
	        10=>array(
	            'name'=>'WhatsApp',
	            'value'=>$list['whatsapp'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'WhatsApp'
	        ),
	        11=>array(
	            'name'=>'Facebook',
	            'value'=>$list['facebook'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'Facebook'
	        ),
	       12=>array(
	            'name'=>'Telegram',
	            'value'=>$list['telegram'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'Telegram'
	        ),
	        13=>array(
	            'name'=>'qq',
	            'value'=>$list['qq'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'qq'
	        ),
	        14=>array(
	            'name'=>'Twitter',
	            'value'=>$list['twitter'],
	            'group'=>'联系方式',
	            'editor'=>'text',
	            'key'=>'Twitter'
	        ),
	        
	    ); */
	    $this->ajaxReturn($data);
	}
    public function editUser(){
        foreach ($_POST as $k=>$v){
            $r[]=M('User')->where(['UE_ID'=>$this->uid])->setField($k,$v);
        }
        if(!$r){
            $data = [
                'status'=>0,
                'info'=>'服务器繁忙'
            ];
        
        }else{
            $data = [
                'status'=>1,
                'info'=>'修改成功'
            ];
           
        }
        $this->ajaxReturn($data);
    }
	//幸福信
	public function xingfuxin() {
		$this->display ('xingfuxin');
	}
	//网络任务
	public function wangluorenwu() {
		$this->display ('wangluorenwu');
	}
	//马夫罗
	public function mafuluo() {
	    $uid =$this->uid;
	    $where['uid'] = $uid;
	    $page = I('page');
	    $num = I('num');
	    $pages = $this->DoPage($page, $num);
	    $list =  M('User_jiangjin')
	    ->where($where)
	    ->order('add_time desc')
	    -> limit($pages['limit'],$pages['num'])
	    ->select();
	    foreach ($list as $k=>$v){
	        $list[$k]['dongjie_time'] = $v['add_time']+($v['frozen_day']*86400);
	        $day = intval((time()-$v['add_time'])/86400);
	        $list[$k]['lixi_money'] = $v['lixi']*$day*$v['money'];
	    }
	    $count = M('User_jiangjin')->where($where)->count();
	    $return = [
	        'count'=>$count,
	        'data'=>$list,
	        'status'=>1
	    ];
	    $this->ajaxReturn($return);
	}
	/**
	 * 处理分页
	 */
	public function DoPage($page,$num){
	    if(empty($page)){
	        $page = 1;
	    }
	    if(empty($num)){
	        $num = 10;
	    }
	    $data = [
	        'page'=>$page,
	        'num'=>$num,
	        'limit'=>($page-1)*$num,
	    ];
	    return $data;
	}
	//账户
	public function zhanghu() {
		$this->display ('zhanghu');
	}
	//激活令牌
	public function jihuolingpai() {
		$this->display ('jihuolingpai');
	}
	//反馈
	public function fankui() {
		$this->display ('fankui');
	}
	//新闻
	public function news() {
		$this->display ('news');
	}
	public function getMafuluoLog(){
		$data['mavro'] = array(
			0=>array(
					'code_number'=>'1',
					'status'=>'MAVRO_NOACTIVE_TYPE',
					'create_date'=>'3',
					'fr'=>'4',
					'mvr'=>'5',
					'mtd'=>'6',
					'descr'=>'7'
				),
		);
		$this->ajaxReturn($data);
	}
	public function getWodeyemianLog(){
		$data = array(
			'42' => 8,
		);
		$this->ajaxReturn($data);
	}
	public function getZhanghuLog(){
	    $uid =$this->uid;
	    $list = M('User_bank')
	   // ->field('id,user as a_n,type_name as cursname,bank_name as real_bankname,bank_num as a_num,bank_user as name')
	    ->where(['uid'=>$uid])->select();
	    $data['data'] = $list;
	    $data['status'] = 1;
	    $this->ajaxReturn($data);
	}
	//添加账户
	public function addZhanghu(){
	    $uid =$this->uid;
	    //$id = I('id');
	    //$email_code = I('email_code');
	    $data['user'] = I('accountName');
	    $data['bank_num'] = I('accountNumber');
	    $data['bank_user'] = I('firstName');
	    $data['bank_name'] = I('addacc_bank_name');
	    $data['type'] = I('addacc_bank_type');
	    switch ($data['type'])
	    {
	        case 840:
	            $data['type_name'] = 'USDT';
	            break;
	        /*  case 850:
	            $data['type_name'] = 'CNY: CNY';
	            break; */
	        /* case 860:
	            $data['type_name'] = 'BCH: Bitcoin';
	            break; */
	    }
	        $data['add_time'] = time();
	        $data['uid'] = $uid;
	        $r = M('User_bank')->add($data);
	        if($r){
	            $return['status'] = 1;
	            $return['info'] = 'Success';
	            $this->ajaxReturn($return);
	        }
	}
	//修改账户
	public function editZhanghu(){
	    $uid =$this->uid;
	    $id = I('id');
	    //$email_code = I('email_code');
	    $data['user'] = I('accountName');
	    $data['bank_num'] = I('accountNumber');
	    $data['bank_user'] = I('firstName');
	    $data['bank_name'] = I('addacc_bank_name');
	    $data['type'] = I('addacc_bank_type');
	    switch ($data['type'])
	    {
	        case 840:
	            $data['type_name'] = 'USDT';
	            break;
	    }
	        $data['add_time'] = time();
	        $data['uid'] = $uid;
	        $r = M('User_bank')->where(['id'=>$id])->save($data);
	        if($r){
	            $return['status'] = 1;
	            $return['info'] = 'Success';
	            $this->ajaxReturn($return);
	        }
	}
	//删除账户
	public function deleteZhanghu(){
	    $id = I('id');
	    $r = M('User_bank')->where(['id'=>$id,'uid'=>$this->uid])->delete();
	    if($r){
	        $return['status'] = 1;
	        $return['info'] = 'Success';
	        $this->ajaxReturn($return);
	    }
	}
	public function getJihuolingpaiLog(){
		$data['codes'] = array(
			0=>array(
					'id'=>'1',
					'a_code'=>'2',
					'c_date'=>'850',
					'u_date'=>'4',
				),
		);
		$this->ajaxReturn($data);
	}
}